package com.gshrms.common.core.domain;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data

@ApiModel(value = "JsonData对象", description = "封装接口返回给前端的数据")
public class CommonResult<T> {
    /**
     * 状态码
     */
    @ApiModelProperty(value = "响应状态码", dataType = "Integer")
    private Integer code;
    /**
     * 数据
     */
    @ApiModelProperty(value = "响应数据")
    private T data;
    /**
     * 状态信息
     */
    @ApiModelProperty(value = "响应提示信息")
    private String msg;

    public CommonResult() {
    }

    public CommonResult(Integer code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <T> CommonResult<T> resultVoid(int i , String v) {
        if (i<=0){
            return new CommonResult(500, null,v+"失败");
        }else {
            return new CommonResult(200, null, v+"成功");
        }
    }

    public static <T> CommonResult<T> resultVoid(boolean i , String v) {
        if (!i){
            return new CommonResult(500, null,v+"失败");
        }else {
            return new CommonResult(200, null, v+"成功");
        }
    }

    public static <T> CommonResult<T> resultVoid(boolean i ) {
        if (!i){
            return new CommonResult(500, null,"操作失败");
        }else {
            return new CommonResult(200, null, "操作成功");
        }
    }



    /**
     * 成功
     */
    public static <T> CommonResult<T> success() {
        return new CommonResult(200, null, null);
    }

    /**
     * 成功
     *
     * @param data 数据
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult(200, data, null);
    }

    /**
     * 成功
     *
     * @param data 数据
     * @param msg  状态信息
     */
    public static <T> CommonResult<T> success(T data, String msg) {
        return new CommonResult(200, data, msg);
    }

    /**
     * 失败
     *
     * @param msg 数据
     */
    public static <T> CommonResult<T> error(String msg) {
        return new CommonResult(500, null, msg);
    }

    /**
     * 失败
     *
     * @param code 状态码
     * @param msg  数据
     */
    public static <T> CommonResult<T> error(Integer code, String msg) {
        return new CommonResult(code, null, msg);
    }

    /**
     * 参数错误
     */
    public static <T> CommonResult<T> validateFailed() {
        return new CommonResult(400, null, "参数错误");
    }

    /**
     * token错误
     */
    public static <T> CommonResult<T> tokenError() {
        return new CommonResult(401, null, "token失效，请重新登录");
    }


    /**
     * 用户名或者密码错误
     */
    public static <T> CommonResult<T> error_402() {
        return new CommonResult(402, null, "用户名或者密码错误");
    }

    /**
     * 未授权的访问
     */
    public static <T> CommonResult<T> error_403() {
        return new CommonResult(403, null, "未授权的访问");
    }

    /**
     * 请求的网页/路径不存在
     */
    public static <T> CommonResult<T> error_404() {
        return new CommonResult(404, null, "请求的网页/路径不存在");
    }


}
